import requests
from urllib import parse
from lxml import etree

start_url = "http://app1.sfda.gov.cn/datasearch/face3/search.jsp"
user_agent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.117 Safari/537.36"
referer = "http://app1.sfda.gov.cn/datasearch/face3/base.jsp?tableId=32&tableName=TABLE32&title=%B9%FA%B2%FA%D2%A9%C6%B7%C9%CC%C6%B7%C3%FB&bcId=124356639813072873644420336632"

headers = {
    'Content-Type': 'application/x-www-form-urlencoded',
    "User-Agent": user_agent,
    "Referer": referer,
    "JSESSIONID": "17B8543C2BC1299E364373B68532C304.7",
    "Host":"app1.sfda.gov.cn",
    "Origin":"http://pp1.sfda.gov.cn"
}

form_data = {
    "tableId": "32",
    "State": "1",
    "bcId": "124356639813072873644420336632",
    "State": "1",
    "curstart": "10",
    "State": "1",
    "tableName": "TABLE32",
    "State": "1",
    "viewtitleName": "COLUMN302",
    "State": "1",
    "viewsubTitleName": "COLUMN303, COLUMN299",
    "State": "1",
    "tableView": parse.quote("国产药品商品名", encoding="utf-8"),
    "State": "1",
    "cid": "0",
    "State": "1",
    "ytableId": "0",
    "State": "1",
    "searchType": "search",
    "State": "1"
}


def parse_list(url, headers, form_data):
    respon = requests.post(url, headers=headers, data=form_data)
    print(respon.content.decode("GBK"))
    with open("./yaojianju.html", "w") as f:
        f.write(respon.content.decode("gb2312"))


def main():
    parse_list(start_url, headers, form_data)


if __name__ == '__main__':
    main()
